package zuo.algo.c02;

import zuo.algo.util.SortUtils;

import java.util.Arrays;

public class SelectionSort {

    public static void sort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            int min = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[min]) {
                    min = j;
                }
            }
            SortUtils.swap(arr, i, min);
        }
    }

    public static void main(String[] args) {
        int maxLen = 10000;
        long begin = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            int[] arr1 = SortUtils.getRandomArr(maxLen);
            int[] arr2 = Arrays.copyOf(arr1, arr1.length);
            Arrays.sort(arr2);
            sort(arr1);
            SortUtils.assertArr(arr1, arr2);
            System.out.println(i);
        }
        System.out.println(System.currentTimeMillis() - begin);
    }
}
